import { createRouter, createWebHistory } from "vue-router";
import routes from "@/router/routes";
import { get_token } from "@/utils/auth";
import { Getemploy } from "@/api/order";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes,
});

//导航守卫
router.beforeEach(async (to, from, next) => {
  if (!to.meta.not_check) {
    if (!get_token()) {
      next("/login");
      return;
    }
    //验证当前登录信息是否过期
    const res = await Getemploy();
    sessionStorage.setItem("curr_user", JSON.stringify(res.data));
  }

  next();
});

export default router;
